﻿CREATE TABLE [dbo].[DisplayControls] (
    [DisplayControlID]    INT IDENTITY (1, 1) NOT NULL,
    [ParentID]            INT NOT NULL,
    [FieldID]             INT NOT NULL,
    [ControlTypeID]       INT NOT NULL,
    [ControlValidationID] INT NOT NULL,
    CONSTRAINT [PK_dbo.DisplayControls] PRIMARY KEY CLUSTERED ([DisplayControlID] ASC),
    CONSTRAINT [FK_dbo.DisplayControls_dbo.ControlTypes_ControlTypeID] FOREIGN KEY ([ControlTypeID]) REFERENCES [dbo].[ControlTypes] ([ControlTypeID]),
    CONSTRAINT [FK_dbo.DisplayControls_dbo.ControlValidations_ControlValidationID] FOREIGN KEY ([ControlValidationID]) REFERENCES [dbo].[ControlValidations] ([ControlValidationID]),
    CONSTRAINT [FK_dbo.DisplayControls_dbo.Fields_FieldID] FOREIGN KEY ([FieldID]) REFERENCES [dbo].[Fields] ([FieldID])
);


GO
CREATE NONCLUSTERED INDEX [IX_FieldID]
    ON [dbo].[DisplayControls]([FieldID] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_ControlTypeID]
    ON [dbo].[DisplayControls]([ControlTypeID] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_ControlValidationID]
    ON [dbo].[DisplayControls]([ControlValidationID] ASC);

